<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script type="text/javascript">
    $(document).ready(function() {
        var currentId = Page.currentId;
        var count = 0;
        var sysInfo_plmn;
        var loading = '-';
        function getPinPukWarning(reqPin, reqPuk){
            if (reqPin == 1) {
                if (reqPuk == 1)
                    warning = PROMPT.tips.pinPukSet;
                else
                    warning = PROMPT.tips.pinSet;
            } else if (reqPuk == 1) {
                warning = PROMPT.tips.pukSet;
            } else {
                warning = "";
            }

            if (Page.isSimLocked && warning != "") {
                warning = PROMPT.tips.simLocked;
            }

            return warning;
        }


        //        function loop(){
//            if(currentId != Page.currentId) return;
//
//            if(count % 5 == 0)
//            {
//                loadPage();
//            }
//            if(count % 60 == 0)
//            {
//                    loadWlanPage();
//                    loadWlan5gPage();
//            }
//            count++;
//            setTimeout(loop, 10000000);
//        }

        function loop() {
            loadPage();
            loadPage2();
            loadPage3();
            // loadPage4();
            loadPage5();
            loadWlanPage();
            loadWlan5gPage();
        }

        function getCardState(flag){
            var stateComment = '-';
            if(flag == 0){
                stateComment = DOC.status.noSim;
            } else if(flag == 1) {
                stateComment = DOC.status.existSim;
            }

            return stateComment;
        }

        function getPINState(flag){
            var stateComment;
            if(flag == 0){
                stateComment = DOC.status.noreqPin;
            } else if(flag == 1) {
                stateComment = DOC.status.repPin;
            } else {
                stateComment = DOC.status.invalid;
            }

            return stateComment;
        }

        function getPUKState(flag){
            var stateComment;
            if(flag == 0){
                stateComment = DOC.status.noreqPuk;
            } else if(flag == 1) {
                stateComment = DOC.status.reqPuk;
            } else {
                stateComment = DOC.status.invalid;
            }

            return stateComment;
        }

        function getPinPukState(flag) {
            var pinState="-",pukState="-";
            if(flag == 0){
                pinState = DOC.status.noreqPin;
                pukState = DOC.status.noreqPuk;
            }else if(flag == 1){
                pinState = DOC.status.repPin;
                pukState = DOC.status.noreqPuk;
            }else if(flag == 2){
                pinState = DOC.status.noreqPin;
                pukState = DOC.status.reqPuk;
            }
            return { pinState: pinState, pukState: pukState };
        }

        function getNetState(flag) {
            var state = "-";
            if(flag == -1){
                state = "?";
            }else if(flag == 0){
                state = "2g";
            }else if(flag == 2){
                state = "3g";
            }else if(flag == 7){
                state = "4g";
            }
            return state;
        }

        function getRegState(flag) {
            var csRegState ="-", psRegState ="-";
            switch(flag) {
                case 0:
                    csRegState = DOC.registerStatus.item0;
                    psRegState = DOC.registerStatus.item0;
                    break;
                case 1:
                    csRegState = DOC.registerStatus.item7;
                    psRegState = DOC.registerStatus.item0;
                    break;
                case 2:
                    csRegState = DOC.registerStatus.item7;
                    psRegState = DOC.registerStatus.item0;
                    break;
                case 3:
                    csRegState = DOC.registerStatus.item7;
                    psRegState = DOC.registerStatus.item7;
                    break;
                default:
                    csRegState = DOC.registerStatus.item8;
                    psRegState = DOC.registerStatus.item8;
                    break;
            }
            return { csRegState: csRegState, psRegState: psRegState };
        }

        function loadPage() {

            Page.postJSON({
                json: { cmd: RequestCmd.SYS_INFO },
                success: function(datas) {
                    var data2 = datas.data;   
                    var data_wan = data2.network;
                     var names_run = [],names_sim = [], names_net = [], names_lan = [], names_wan = [],names_lte = [];
                    var values_run = [], values_sim = [], values_net = [], values_lan = [], values_wan = [], values_lte = [];
                    Page.isNULLToSpace = true;

                  //  var ps_cs = parseInt(data_modem.ps_cs, 10);
                  //  var regState = getRegState(ps_cs);
                  //  values_net.push(regState.csRegState);
                  //  values_net.push(regState.psRegState);
                 // //  values_net.push(netState == "3G" ? DOC.status.noreg : StatusUtil.getRegState(data.eregStat));
                 //   values_net.push("-");

                    names_wan.push(DOC.net.mac);
                    names_wan.push(DOC.net.ip);
                    names_wan.push(DOC.net.mask);
                    names_wan.push(DOC.net.gateway);
                    names_wan.push(DOC.net.dns1);
                    names_wan.push(DOC.net.dns2);


                    values_wan.push(data_wan.mac || loading);
                    values_wan.push(data_wan.ipaddr || loading);
                    values_wan.push(data_wan.netmask || loading);
                    values_wan.push(data_wan.gateway || loading);
                    if(data_wan.ipaddr == undefined){
                            values_wan.push("-");
                            values_wan.push("-");
                    } else {
                            values_wan.push(data_wan.first_dns || loading);
                            values_wan.push(data_wan.second_dns || loading);
                    }
                    
                    names_wan.push(DOC.net.rxPackets);
                    names_wan.push(DOC.net.rxBytes);
                    names_wan.push(DOC.net.txPackets);
                    names_wan.push(DOC.net.txBytes);
                    // names_wan.push(wan_text.manageTime);

                    values_wan.push(data_wan.rx_packets || loading);
                    values_wan.push(data_wan.rx_bytes || loading);
                    values_wan.push(data_wan.tx_packets || loading);
                    values_wan.push(data_wan.tx_bytes || loading);
                    // var manageTime = parseInt(data.manageTime.trim());
                    // var theUptime = parseInt(data.theUptime.trim());
                    // if (!isNaN(manageTime) && !isNaN(theUptime)) {
                    // 	var millseconds = new Date().getTime() - (theUptime - manageTime) * 1000;
                    // 	var manageDate = new Date(millseconds);
                    // 	values_wan.push(manageDate.format("yyyy-mm-dd HH:MM:ss"));
                    // } else {
                    // 	values_wan.push(data.manageTime);
                    // }
                    //  var  warningsss = getWanState(data.showMode);

                    //if (warningsss != ""){
                    //  var stateWan = String.format('<span style="color:black;"> &nbsp;{0}</span>', warningsss);
					
                    
                   
                   
                    var wan_html = Page.createTable(DOC.title.wan, names_wan, values_wan, names_wan.length, 2).replace("<td>", "<td style=\"width:32%;\">");
                    $('#wan_info').html(wan_html);
                    

                   // Page.setStripeTable();
                    Page.isNULLToSpace = false;
                }
            });


        }

        function loadPage2() {

            Page.postJSON({
                json: { cmd: RequestCmd.SYS_INFO_2},
                success: function(datas) {
                    Page.isNULLToSpace = true;
                    var data2 = datas.data;
                    var data_system = data2.system;
                     var names_run = [],names_sim = [], names_net = [], names_lan = [], names_wan = [],names_lte = [];
                    var values_run = [], values_sim = [], values_net = [], values_lan = [], values_wan = [], values_lte = [];
                    names_run.push(DOC.lbl.runtime);
                    names_run.push(DOC.lbl.loadAvg);
//                    names_run.push(run_text.currentSys);
                    names_run.push(DOC.lbl.memory);

                     var runtime = ConvertUtil.timeStamp(data_system.runtime || 0);
                    values_run.push(runtime);
                    values_run.push((data_system.cpu_average1 || loading) + ", " + (data_system.cpu_average5 || loading) + ", " + (data_system.cpu_average15 || loading));
                    values_run.push("MemTotal "+ (data_system.mem_total ? FormatUtil.formatField(data_system.mem_total, 'KB') : loading) +
                                    "MemFree " + (data_system.mem_free ? FormatUtil.formatField(data_system.mem_free, 'KB') : loading) +
                                    "Cached  " + (data_system.mem_cache ? FormatUtil.formatField(data_system.mem_cache, 'KB') : loading));
                    var run_html = Page.createTable(DOC.title.run, names_run, values_run, names_run.length, 2).replace("<td>", "<td style=\"width:32%;\">");
                     $('#run_info').html(run_html);
                     Page.isNULLToSpace = false;
                }
            })
        }
        function loadPage3() {

            Page.postJSON({
                json: { cmd: RequestCmd.SYS_INFO_3},
                success: function(datas) {

                    var names_run = [],names_sim = [], names_net = [], names_lan = [], names_wan = [],names_lte = [];
                    var values_run = [], values_sim = [], values_net = [], values_lan = [], values_wan = [], values_lte = [];
                    Page.isNULLToSpace = true;

                    var data2 = datas.data;
                    var data_modem = data2.modem;
                    names_net.push(DOC.lbl.netMode);
                    names_net.push(DOC.lbl.signal);
                   // names_net.push(DOC.lbl.signalLevel);
                  //  names_net.push(DOC.lbl.plmn);
                  //  names_net.push(DOC.lbl.regState);
                  //    names_net.push(DOC.lbl.psReg);
                  //   names_net.push(DOC.lbl.epsReg);
                 
                    names_net.push(DOC.lte.rsrp);
                    names_net.push(DOC.lte.rssi);
                    names_net.push(DOC.lte.rsrq);
                    names_net.push(DOC.lte.sinr);
                    names_net.push(DOC.lte.phyCellId);
                    names_net.push(DOC.lte.freqPoint);
                    names_net.push(DOC.lte.enodeB);
                    names_net.push(DOC.lte.cellId);
                    names_net.push(DOC.lte.cqi);
                    names_net.push(DOC.lte.mcs);
                    names_net.push(DOC.lte.plmn);

                    //var netState = StatusUtil.getNetState(data.signalLevel, data.eregStat, data.act, 0);
                    var netState = getNetState(data_modem.act);
                    var singalLevel = data_modem.signal_lvl;

                    // 网络都注册失败时显示未知
                    // if (!StatusUtil.isAnyRegSuccess(data.regStat, data.gregStat, data.eregStat)) {
                    //  netState = "?";
                    //  singalLevel = 0;
                    // }
                    values_net.push(netState);
                    values_net.push(StatusUtil.formatSingalLevel(singalLevel));
                   // values_net.push(data_modem.rsrp || loading);

                  //  values_net.push(FormatUtil.formatPLMN(data_modem.plmn));
                    
                    values_net.push(data_modem.rsrp ? FormatUtil.formatField(data_modem.rsrp, 'dBm') : loading);
                    values_net.push(data_modem.rssi ? FormatUtil.formatField(data_modem.rssi, 'dBm') : loading);
                    values_net.push(data_modem.rsrq ? FormatUtil.formatField(data_modem.rsrq, 'dB') : loading);
                    values_net.push(data_modem.sinr ? FormatUtil.formatField(data_modem.sinr, 'dB') : loading);
                    values_net.push(data_modem.pci || loading);
                    values_net.push(data_modem.earfcn ||loading);
                    values_net.push(data_modem.enodebid || loading);
                    values_net.push(data_modem.cell_id || loading);
                    values_net.push(data_modem.cqi || loading);
                    values_net.push(data_modem.mcs ||loading);
                    values_net.push(data_modem.plmn || loading);
                    sysInfo_plmn = data_modem.plmn; 
                     var net_html = Page.createTable(DOC.title.network, names_net, values_net, names_net.length, 2).replace("<td>", "<td style=\"width:32%;\">");
                     $('#net_info').html(net_html);
                     Page.isNULLToSpace = false;
                     return sysInfo_plmn;
                }
            })
        }
        function loadPage4() {

            Page.postJSON({
                json: { cmd: RequestCmd.SYS_INFO_4},
                success: function(datas) {
                    var names_run = [],names_sim = [], names_net = [], names_lan = [], names_wan = [],names_lte = [];
                    var values_run = [], values_sim = [], values_net = [], values_lan = [], values_wan = [], values_lte = [];
                    Page.isNULLToSpace = true;
                    
                    var data2 = datas.data;
                    var data_sim = data2.sim;
                    names_sim.push(DOC.lbl.usim);
                   // names_sim.push(DOC.lbl.pinCode);
                   // names_sim.push(DOC.lbl.pukCode);
                    names_sim.push(DOC.device.imsi);
                    names_sim.push(DOC.device.iccid);
                    names_sim.push(DOC.lbl.plmn);

                    var stateInfo = "";
                   // var pinPukStateInfo = getPinPukState(data_sim.card_status);
                    values_sim.push(getCardState(data_sim.is_sim_exist));
                  //  values_sim.push(pinPukStateInfo.pinState);
                  //  values_sim.push(pinPukStateInfo.pukState);
                  
                    values_sim.push(data_sim.imsi || loading);
                    values_sim.push(data_sim.iccid || loading);
                    values_sim.push(FormatUtil.formatPLMN(sysInfo_plmn));
                     var sim_html = Page.createTable(DOC.title.sim + stateInfo, names_sim, values_sim, names_sim.length, 2).replace("<td>", "<td style=\"width:32%;\">");
                     $('#sim_info').html(sim_html);
                    Page.isNULLToSpace = false;
                }
            })
        }
        function loadPage5() {

            Page.postJSON({
                json: { cmd: RequestCmd.SYS_INFO_5},
                success: function(datas) {
                    var names_run = [],names_sim = [], names_net = [], names_lan = [], names_wan = [],names_lte = [];
                    var values_run = [], values_sim = [], values_net = [], values_lan = [], values_wan = [], values_lte = [];
                    Page.isNULLToSpace = true;
                    var data2 = datas.data;
                    var data_lan = data2.lan;
                    names_lan.push(DOC.net.mac);
                    names_lan.push(DOC.net.ip);
                    names_lan.push(DOC.net.mask);

                    values_lan.push(data_lan.lan_mac || loading);

                    Page.lanIp = data_lan.server_ip;
                    values_lan.push(data_lan.server_ip || loading);
                    values_lan.push(data_lan.netmask || loading);

                    names_lan.push(DOC.net.dhcpServer);
                    var dhcp = data_lan.enable ? '1' : '0';
                    if(dhcp == DHCPServer.CLOSED){
                        values_lan.push(DOC.status.closed);
                    } else {
                        values_lan.push(DOC.status.opened);
                    }
                    var lan_html = Page.createTable(DOC.title.lan, names_lan, values_lan, names_lan.length, 2).replace("<td>", "<td style=\"width:32%;\">");
                    $('#lan_info').html(lan_html);
                    Page.isNULLToSpace = false;
                }
            })
        }





        function getWlanSecMode(encry)
        {
            var secMode = "None";

            switch (encry){
                case "none" :
                    secMode = "None";
                    break;
                case "wep" :
                    secMode = "wep";
                    break;
                case "psk" :
                    secMode = "wpa-psk";
                    break;
                case "psk2" :
                    secMode = "wpa2-psk";
                    break;
                case "mixed" :
                    secMode = "wpa/wpa2-psk";
                    break;
            }

            return secMode;
        }

        function getWlanMode(mode) {
            var secMode;
            switch (mode){
                case 0 :
                    secMode = "legacy 11b/g mixed";
                    break;
                case 1 :
                    secMode = "legacy 11b only";
                    break;
                case 2 :
                    secMode = "legacy 11a only";
                    break;
                case 3 :
                    secMode = "legacy 11a/b/g mixed";
                    break;
                case 4 :
                    secMode = "legacy 11g only";
                    break;
                case 5 :
                    secMode = "11abgn mixed";
                    break;
                case 6 :
                    secMode = "11N";
                    break;
                case 7 :
                    secMode = "11gn mixed";
                    break;
                case 8 :
                    secMode = "11an mixed";
                    break;
                case 9 :
                    secMode = "11bgn mixed";
                    break;
                case 10 :
                    secMode = "11AGN mixed";
                    break;
                case 11 :
                    secMode = "11A";
                    break;
                case 14 :
                    secMode = "11NA";
                    break;
                case 15 :
                    secMode = "11AC";
                    break;
                default :
                    secMode = "ap";
                    break;
            }

            return secMode;
        }

        function loadWlanPage() {
            Page.postJSON({
                json: {cmd: RequestCmd.WIFI_INFO},
                success: function (datas) {
                    var data = {"mode":"Master","message":"WLAN未开启"};
                    var wirelessHtml = "";
                    if (data.mode.trim() == "NULL") {
                        wirelessHtml = Page.createTable(DOC.title.wlan2g + '-' + data.message, [], [], 0, 0);
                    } else {
                        var names = [];
                        var values = [];
                        var data2 = datas.data;
                        names.push(DOC.wlan.currentMode);
                        var mode = getWlanMode(parseInt(data2.mode));
                        values.push(mode);

                        names.push(DOC.wlan.wifi);
                        if(data2.status == "0"){
                            values.push(DOC.status.opened);
                        } else {
                            values.push(DOC.status.closed);
                        }

                        names.push(DOC.wlan.ssid);
                        values.push(data2.ssid || loading);

                        names.push(DOC.net.mac);
                        values.push(data2.mac || loading);

                        names.push(DOC.wlan.ssidBroadcast);
                        if(data2.hidden_ssid == "0"){
                            values.push(DOC.status.opened);
                        } else {
                            values.push(DOC.status.closed);
                        }

                       names.push(DOC.wlan.secMode);
                        if(data2.encryption){
                            var encryp = data2.encryption.split("+")[0];
                            values.push(getWlanSecMode(encryp));
                        }else{
                            values.push(loading);
                        }

                        //values.push(FormatUtil.formatField(getWlanSecMode(data.encKey.trim(), data.wpa.trim(), data.wpaKeyMgmt.trim(), data.wpaPairwise.trim())));

                        names.push(DOC.wlan.channel);
                        values.push(data2.channel || loading);

                        names.push(DOC.wlan.txPower);
                        values.push(data2.txpower ? FormatUtil.formatField(data2.txpower, "dBm") : loading);


                        wirelessHtml = Page.createTable(DOC.title.wlan2g, names, values, names.length, 2).replace("<td>", "<td style=\"width:32%;\">");
                    }
                    $('#wlan_info').html(wirelessHtml);
                    Page.setStripeTable("#wlan_info");
                }
            });

        }

        function loadWlan5gPage() {
            Page.postJSON({
                json: {cmd: RequestCmd.WIFI5_INFO},
                success: function (datas) {
                    var data = {"mode":"Master","message":"WLAN未开启"};
                    var wlan5gHtml = "";
                    if (data.mode.trim() == "NULL") {
                        wlan5gHtml = Page.createTable(DOC.title.wlan5g + data.message, [], [], 0, 0);
                    } else {
					  
                        var names = [];
                        var values = [];
                        var data2 = datas.data;
                        names.push(DOC.wlan.currentMode);
						var mode = getWlanMode(parseInt(data2.mode));
                        values.push(mode);

                        names.push(DOC.wlan.wifi);
                        if(data2.status == "0")
                            values.push(DOC.status.opened);
                        else
                            values.push(DOC.status.closed);

                        names.push(DOC.wlan.ssid);
                        values.push(data2.ssid || loading);

                        names.push(DOC.net.mac);
                        values.push(data2.mac || loading);

                        names.push(DOC.wlan.ssidBroadcast);
                        if(data2.hidden_ssid == "0"){
                            values.push(DOC.status.opened);
                        } else {
                            values.push(DOC.status.closed);
                        }

                        names.push(DOC.wlan.secMode);
                        if(data2.encryption){
                            var encryp = data2.encryption.split("+")[0];
                            values.push(getWlanSecMode(encryp));
                        }else{
                            values.push(loading);
                        }

                        names.push(DOC.wlan.channel);
                        values.push(data2.channel || loading);

                        names.push(DOC.wlan.txPower);
                        values.push(data2.txpower ? FormatUtil.formatField(data2.txpower, "dBm") : loading);
                                 
                        wlan5gHtml = Page.createTable(DOC.title.wlan5g, names, values, names.length, 2).replace("<td>", "<td style=\"width:32%;\">");
                    }
					
                    $('#wlan_5g_info').html(wlan5gHtml);
                    Page.setStripeTable("#wlan_5g_info");
                }
            });

        }

        loop();

        $('#net_info').click(function(e){
            if(e.target.id == "net_connect"){
                if(!AlertUtil.confirm(prompt.item1)){
                    return false;
                }

                Page.postJSON({
                    json:{
                        cmd: RequestCmd.NET_CONNECT
                    },
                    success: function(){

                    },
                    complete: function(){
                        count = 2;
                        Page.connectStatus = true;
                        $('#connectPrompt').html(prompt.item2);
                    }
                });
            } else if(e.target.id == "net_disconnect"){
                if(!AlertUtil.confirm(prompt.item3)){
                    return false;
                }
                Page.postJSON({
                    json:{
                        cmd: RequestCmd.NET_DISCONNECT
                    },
                    success: function(){

                    },
                    complete: function(){
                        count = 2;
                        Page.connectStatus = false;
                        $('#connectPrompt').html(prompt.item4);
                    }
                });
            }
        });
    });
</script>

<div class="detail_box">
    <div id="run_info"></div>
    <div id="net_info"></div>
    <div id="sim_info"></div>
    <div id="wan_info"></div>
    <div id="lan_info"></div>
    <div id="wlan_info"></div>
    <div id="wlan_5g_info"></div>
</div>